﻿using System;
public interface IShape//形状接口以及求面积
{
    double CalculateArea();
}
public class Circle : IShape//形状类
{
    private double radius;

    public Circle(double radius)
    {
        this.radius = radius;
    }

    public double CalculateArea()
    {
        return Math.PI * radius * radius;
    }
}

public class Square : IShape//形状类
{
    private double side;

    public Square(double side)
    {
        this.side = side;
    }

    public double CalculateArea()
    {
        return side * side;
    }
}

public class Rectangle : IShape//形状类
{
    private double width;
    private double height;

    public Rectangle(double width, double height)
    {
        this.width = width;
        this.height = height;
    }

    public double CalculateArea()
    {
        return width * height;
    }
}
public class ShapeFactory//定义工厂
{
    public static IShape CreateShape(string type, params double[] args)
    {
        switch (type.ToLower())
        {
            case "circle":
                return new Circle(args[0]);
            case "square":
                return new Square(args[0]);
            case "rectangle":
                return new Rectangle(args[0], args[1]);
            default:
                throw new ArgumentException("Invalid shape type");
        }
    }
}
class Program//Main函数
{
    static void Main()
    {
        Random rand = new Random();
        double totalArea = 0;

        for (int i = 0; i < 10; i++)
        {
            string[] types = { "circle", "square", "rectangle" };
            string type = types[rand.Next(types.Length)];
            double[] args = new double[2];

            switch (type)
            {
                case "circle":
                    args[0] = rand.NextDouble() * 10;
                    break;
                case "square":
                    args[0] = rand.NextDouble() * 10;
                    break;
                case "rectangle":
                    args[0] = rand.NextDouble() * 10;
                    args[1] = rand.NextDouble() * 10;
                    break;
            }

            IShape shape = ShapeFactory.CreateShape(type, args);
            double area = shape.CalculateArea();
            totalArea += area;

            Console.WriteLine($"{type} 面积为： = {area}");
        }

        Console.WriteLine($"总面积为 = {totalArea}");
    }
}